#ifndef __FIIP_H
#define __FIIP_H
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "./fiipListener.h"
#include "./fiipRetransmit.h"
#include "./frame/format.h"
#include "./link/link.h"
#include "./link/route.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
  uint8_t type;
  void (*solve)(Format_FieldStruct*, LinkCfgStruct*);
} ProtocolStruct;  //通信协议结构

extern uint8_t fiip_centerId[8];
extern uint8_t fiip_broadId[8];
extern FormatStruct* fiip_rxd;

void fiip_init(uint8_t relay);
void fiip_setId(uint8_t* id);
void fiip_addProtocol(uint8_t type, ProtocolStruct* protocol);
ProtocolStruct* fiip_getProtocol(uint8_t type);
void fiip_sendOriginal(uint8_t* data, uint16_t dataLen, LinkCfgStruct* link);
void fiip_broadcast(FormatStruct* frame);
void fiip_request(FormatStruct* frame, uint8_t* id, LinkCfgStruct* link);
void fiip_respond(FormatStruct* frame,
                  Format_FieldStruct* msg,
                  uint8_t error,
                  uint8_t* body,
                  uint8_t bodyLen);
void fiip_recv(uint8_t* buf, uint16_t bufLen, LinkCfgStruct* link);
void fiip_connect(uint8_t* id, LinkCfgStruct* link);

#ifdef __cplusplus
}
#endif
#endif  //__FIIP_H
